home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
CAccordionPane 1.0
/
parser.c
< prev
next >
Wrap
Text File
|
1993-05-03
|
6KB
|
300 lines
/******************************************************************************
Parser.c
This is a small parse for the CAccodionPaneDemoDir. It parses and
interperts a small pane structure language. It can build a structure of
arbitary complexity if you have the time to display it!
The language definition is
start = list
list = ( vertical | horizontal ) subpanes '.'
subpanes = subpane*
subpane = fixed | elastic | list
vertical = 'V' poriton
horizontal = 'H' portion
fixed = 'F' size
elastic = 'E' protion
size = pixel count
portion = <cardinal number>
However, the implementation is not so ridged.
To use, call MakePanes() passing the enclosure and the program. For example,
thePane = new CPane;
thePane->IPane(...)
MakePanes( thePane, "V 1 E 1 F 25 E 2 ." );
This will enclose in thePane a CVAccordionPane with three sub-panes. The
first and thrid sub-panes are elastic while the second has a fixed with of
25 pixels. The first elastic sub-pane should be given 1/3 of the height
while the second elastic sub-pane 2/3 of the height.
NOTE: All vertical and horizontal panes are elastic. This is a restriction
of the parser and not the accordion classes.
NOTE: There is almost no error checking.
AUTHOR: Andrew_Gilmartin@Brown.Edu
REVISION: 1
******************************************************************************/
#include "CAccordionPane.h"
#include "Parser.h"
void MakePanes( CPane* anEnclosure, char* program )
{
MakeList( anEnclosure, SkipSpace( program ) );
((CPane*)(anEnclosure->itsSubviews->FirstItem()))->FitToEnclosure( TRUE, TRUE );
} /* MakePanes */
char* MakeList( CPane* anEnclosure, char* program )
{
while ( *program != '.' && *program != '\0' )
{
switch ( *program )
{
case 'V':
program = MakeVertPane( anEnclosure, NextToken( program ) );
break;
case 'H':
program = MakeHorizPane( anEnclosure, NextToken( program ) );
break;
case 'F':
program = MakeFixedPane( anEnclosure, NextToken( program ) );
break;
case 'E':
program = MakeElasticPane( (CAccordionPane*) anEnclosure, NextToken( program ) );
break;
default:
Failure( -1, 0 );
}
}
return NextToken( program );
} /* MakeList */
char* MakeVertPane( CPane* anEnclosure, char* program )
{
CVAccordionPane* thePane;
thePane = new CVAccordionPane;
thePane->IVAccordionPane
( anEnclosure
, anEnclosure->itsSupervisor
, 0, 0 // size
, 0, 0 // offset
, sizELASTIC
, sizELASTIC );
thePane->SetWantsClicks( TRUE );
return MakeList( thePane, NextToken( program ) );
} /* MakeVertPane */
char* MakeHorizPane( CPane* anEnclosure, char* program )
{
CHAccordionPane* thePane;
thePane = new CHAccordionPane;
thePane->IHAccordionPane
( anEnclosure
, anEnclosure->itsSupervisor
, 0, 0 // size
, 0, 0 // offset
, sizELASTIC
, sizELASTIC );
thePane->SetWantsClicks( TRUE );
return MakeList( thePane, NextToken( program ) );
} /* MakeHorizPane */
CPane* MakePane
( CView* anEnclosure
, short aWidth
, short aHeight
, SizingOption hSizing
, SizingOption vSizing )
{
#if FALSE
CPane* thePane;
CPaneBorder* theBorder;
Rect kBorderMargin = { 1, 1, -1, -1 };
//Rect kBorderMargin = { 0, 0, 0, 0 };
thePane = new CPane;
thePane->IPane
( anEnclosure
, anEnclosure->itsSupervisor
, aWidth
, aHeight
, 0
, 0
, hSizing, vSizing );
theBorder = new CPaneBorder;
theBorder->IPaneBorder( kBorderFrame );
theBorder->SetMargin( &kBorderMargin );
theBorder->SetPattern( gray );
thePane->SetBorder( theBorder );
return thePane;
#else
CScrollPane* theScrollPane;
CEditText* theEditPane;
CPaneBorder* theBorder;
Rect kBorderMargin = { 0, 0, 0, 0 };
theScrollPane = new CScrollPane;
theScrollPane->IScrollPane
( anEnclosure
, anEnclosure->itsSupervisor
, aWidth
, aHeight
, 0
, 0
, hSizing
, vSizing
, TRUE, TRUE, FALSE );
theBorder = new CPaneBorder;
theBorder->IPaneBorder( kBorderTop + kBorderLeft );
theBorder->SetMargin( &kBorderMargin );
//theScrollPane->SetBorder( theBorder );
theEditPane = new CEditText;
theEditPane->IEditText
( theScrollPane
, theScrollPane->itsSupervisor
, 0
, 0
, 0
, 0
, sizELASTIC
, sizELASTIC
, 0 );
theEditPane->FitToEnclosure( TRUE, TRUE );
theScrollPane->InstallPanorama( theEditPane );
return theScrollPane;
#endif
} /* MakePane */
char* MakeFixedPane( CView* anEnclosure, char* program )
{
short size = NumberFromStream( program );
if ( member( anEnclosure, CVAccordionPane ) )
{
MakePane
( anEnclosure
, 0 // width
, size // height
, sizELASTIC
, sizFIXEDSTICKY );
}
else
{
MakePane
( anEnclosure
, size // width
, 0 // height
, sizFIXEDSTICKY
, sizELASTIC );
}
return NextToken( program );
} /* MakeFixedPane */
char* MakeElasticPane( CAccordionPane* anEnclosure, char* program )
{
CPane* thePane = MakePane
( anEnclosure
, 0 // width
, 0 // height
, sizELASTIC
, sizELASTIC );
anEnclosure->SetSubviewPortion( thePane, NumberFromStream( program ), FALSE );
return NextToken( program );
} /* MakeElasticPane */
short NumberFromStream( char* stream )
{
short number = 0;
while ( '0' <= *stream && *stream <= '9' )
{
number = number * 10 + ( *stream - '0' );
stream++;
}
return number;
} /* NumberFromStream */
char* SkipSpace( char* stream )
{
while ( *stream == ' ' || *stream == '\r' || *stream == '\t' )
stream++;
return stream;
} /* SkipSpace */
char* SkipToken( char* stream )
{
while ( *stream != ' ' && *stream != '\r' && *stream != '\t' && *stream != '\0' )
stream++;
return stream;
} /* SkipToken */
char* NextToken( char* stream )
{
return SkipSpace( SkipToken( stream ) );
} /* NextToken */